在 function 的命名上時常犯的錯會以過度簡單的命名,造成無法理解該 function 做的事
BAD
const fetchData = {
....
}
const totalOfItems ={
....
}
GOOD
const fetchUserData = {
....
}
const calculateTotal = {
....
}
ex:
function App(){
//父組件
const handleButtonClick = {
.....
}
<div>
<Button onClick={handleButtonClick}/>
</div>
}
function ({onClick}){
//子組件
<button onClick={onClick}></button>
}
-------------------------------------------------------------------------------
//父組件範例
BAD
const deleteUser = ()=>{
....
}
const submit =()=>{
.....
}
GOOD
const handleUserDelete = ()=>{
....
}
const handleSubmit =()=>{
.....
}
//子組件範例
BAD
const buttonClick = ()=>{
....
}
const submit = ()=>{
....
}
GOOD
const onButtonClick = ()=>{
.....
}
const onSubmit = ()=>{
....
}
BAD
const useWindow = ()=>{
....
}
GOOD
const useWindowWidth = ()=>{
....
}
https://hackernoon.com/the-art-of-naming-variables-52f44de00aad
https://jaketrent.com/post/naming-event-handlers-react
https://reactjs.org/docs/handling-events.html